package com.fansl.allround.upms.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fansl.allround.common.core.util.R;
import com.fansl.allround.common.security.annotation.Inner;
import com.fansl.allround.upms.api.entity.SysLog;
import com.fansl.allround.upms.service.SysLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author fansl
 * @Description: 日志表 前端控制器
 * @date 2019/7/12 10:04
 */
@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private SysLogService sysLogService;

    /**
     * 简单分页查询
     *
     * @param page   分页对象
     * @param sysLog 系统日志
     * @return
     */
    @GetMapping("/page")
    public R getLogPage(Page page, SysLog sysLog) {
        return new R<>(sysLogService.page(page, Wrappers.query(sysLog)));
    }

    /**
     * 删除日志
     *
     * @param id ID
     * @return success/false
     */
    @com.fansl.allround.common.log.annotation.SysLog("删除日志")
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Long id) {
        return new R<>(sysLogService.removeById(id));
    }

    @Inner
    @PostMapping
    public R save(@Valid @RequestBody SysLog sysLog) {
        return new R<>(sysLogService.save(sysLog));
    }
}
